package array;

public class MyStack<E> implements Stack<E>{

    MyArray<E> array;

    public MyStack(int capacity) {
       array = new MyArray<E>(capacity);
    }

    public MyStack() {
        array = new MyArray<E>();
    }

    @Override
    public int getSize() {

        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public void push(E e)  {
        array.addLast(e);
    }

    @Override
    public E pop() {
        return array.removeLast();
    }

    @Override
    public E peek() {
        return array.getLast();
    }

    public int getCapacity(){
        return array.getCapacity();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();

        sb.append("Stack");
        sb.append("[");
        for (int i = 0; i < array.getSize(); i++) {
            sb.append(array.get(i));
            if(i != array.getSize()-1){
                sb.append(",");
            }
        }
        sb.append("] top");
        return sb.toString();
    }
}
